home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_elisp-manual-19.idb / usr / freeware / info / elisp-26.z / elisp-26 (.txt)
GNU Info File  |  1998-05-26  |  48KB  |  877 lines

  1. This is Info file elisp, produced by Makeinfo-1.63 from the input file
  2. elisp.texi.
  3.    This version is the edition 2.4.2 of the GNU Emacs Lisp Reference
  4. Manual.  It corresponds to Emacs Version 19.34.
  5.    Published by the Free Software Foundation 59 Temple Place, Suite 330
  6. Boston, MA  02111-1307  USA
  7.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996 Free Software
  8. Foundation, Inc.
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that this permission notice may be stated in a
  19. translation approved by the Foundation.
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the section entitled "GNU General Public License" is included
  23. exactly as in the original, and provided that the entire resulting
  24. derived work is distributed under the terms of a permission notice
  25. identical to this one.
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that the section entitled "GNU General Public License"
  29. may be included in a translation approved by the Free Software
  30. Foundation instead of in the original English.
  31. File: elisp,  Node: Near Point,  Next: Buffer Contents,  Up: Text
  32. Examining Text Near Point
  33. =========================
  34.    Many functions are provided to look at the characters around point.
  35. Several simple functions are described here.  See also `looking-at' in
  36. *Note Regexp Search::.
  37.  - Function: char-after POSITION
  38.      This function returns the character in the current buffer at (i.e.,
  39.      immediately after) position POSITION.  If POSITION is out of range
  40.      for this purpose, either before the beginning of the buffer, or at
  41.      or beyond the end, then the value is `nil'.
  42.      In the following example, assume that the first character in the
  43.      buffer is `@':
  44.           (char-to-string (char-after 1))
  45.                => "@"
  46.  - Function: following-char
  47.      This function returns the character following point in the current
  48.      buffer.  This is similar to `(char-after (point))'.  However, if
  49.      point is at the end of the buffer, then `following-char' returns 0.
  50.      Remember that point is always between characters, and the terminal
  51.      cursor normally appears over the character following point.
  52.      Therefore, the character returned by `following-char' is the
  53.      character the cursor is over.
  54.      In this example, point is between the `a' and the `c'.
  55.           ---------- Buffer: foo ----------
  56.           Gentlemen may cry ``Pea-!-ce! Peace!,''
  57.           but there is no peace.
  58.           ---------- Buffer: foo ----------
  59.           
  60.           (char-to-string (preceding-char))
  61.                => "a"
  62.           (char-to-string (following-char))
  63.                => "c"
  64.  - Function: preceding-char
  65.      This function returns the character preceding point in the current
  66.      buffer.  See above, under `following-char', for an example.  If
  67.      point is at the beginning of the buffer, `preceding-char' returns
  68.      0.
  69.  - Function: bobp
  70.      This function returns `t' if point is at the beginning of the
  71.      buffer.  If narrowing is in effect, this means the beginning of the
  72.      accessible portion of the text.  See also `point-min' in *Note
  73.      Point::.
  74.  - Function: eobp
  75.      This function returns `t' if point is at the end of the buffer.
  76.      If narrowing is in effect, this means the end of accessible
  77.      portion of the text.  See also `point-max' in *Note Point::.
  78.  - Function: bolp
  79.      This function returns `t' if point is at the beginning of a line.
  80.      *Note Text Lines::.  The beginning of the buffer (or its accessible
  81.      portion) always counts as the beginning of a line.
  82.  - Function: eolp
  83.      This function returns `t' if point is at the end of a line.  The
  84.      end of the buffer (or of its accessible portion) is always
  85.      considered the end of a line.
  86. File: elisp,  Node: Buffer Contents,  Next: Comparing Text,  Prev: Near Point,  Up: Text
  87. Examining Buffer Contents
  88. =========================
  89.    This section describes two functions that allow a Lisp program to
  90. convert any portion of the text in the buffer into a string.
  91.  - Function: buffer-substring START END
  92.      This function returns a string containing a copy of the text of the
  93.      region defined by positions START and END in the current buffer.
  94.      If the arguments are not positions in the accessible portion of
  95.      the buffer, `buffer-substring' signals an `args-out-of-range'
  96.      error.
  97.      It is not necessary for START to be less than END; the arguments
  98.      can be given in either order.  But most often the smaller argument
  99.      is written first.
  100.      If the text being copied has any text properties, these are copied
  101.      into the string along with the characters they belong to.  *Note
  102.      Text Properties::.  However, overlays (*note Overlays::.) in the
  103.      buffer and their properties are ignored, not copied.
  104.           ---------- Buffer: foo ----------
  105.           This is the contents of buffer foo
  106.           
  107.           ---------- Buffer: foo ----------
  108.           
  109.           (buffer-substring 1 10)
  110.           => "This is t"
  111.           (buffer-substring (point-max) 10)
  112.           => "he contents of buffer foo
  113.           "
  114.  - Function: buffer-substring-no-properties START END
  115.      This is like `buffer-substring', except that it does not copy text
  116.      properties, just the characters themselves.  *Note Text
  117.      Properties::.  Here's an example of using this function to get a
  118.      word to look up in an alist:
  119.           (setq flammable
  120.                 (assoc (buffer-substring start end)
  121.                        '(("wood" . t) ("paper" . t)
  122.                          ("steel" . nil) ("asbestos" . nil))))
  123.      If this were written using `buffer-substring' instead, it would not
  124.      work reliably; any text properties that happened to be in the word
  125.      copied from the buffer would make the comparisons fail.
  126.  - Function: buffer-string
  127.      This function returns the contents of the accessible portion of the
  128.      current buffer as a string.  This is the portion between
  129.      `(point-min)' and `(point-max)' (*note Narrowing::.).
  130.           ---------- Buffer: foo ----------
  131.           This is the contents of buffer foo
  132.           
  133.           ---------- Buffer: foo ----------
  134.           
  135.           (buffer-string)
  136.                => "This is the contents of buffer foo
  137.           "
  138. File: elisp,  Node: Comparing Text,  Next: Insertion,  Prev: Buffer Contents,  Up: Text
  139. Comparing Text
  140. ==============
  141.    This function lets you compare portions of the text in a buffer,
  142. without copying them into strings first.
  143.  - Function: compare-buffer-substrings BUFFER1 START1 END1 BUFFER2
  144.           START2 END2
  145.      This function lets you compare two substrings of the same buffer
  146.      or two different buffers.  The first three arguments specify one
  147.      substring, giving a buffer and two positions within the buffer.
  148.      The last three arguments specify the other substring in the same
  149.      way.  You can use `nil' for BUFFER1, BUFFER2, or both to stand for
  150.      the current buffer.
  151.      The value is negative if the first substring is less, positive if
  152.      the first is greater, and zero if they are equal.  The absolute
  153.      value of the result is one plus the index of the first differing
  154.      characters within the substrings.
  155.      This function ignores case when comparing characters if
  156.      `case-fold-search' is non-`nil'.  It always ignores text
  157.      properties.
  158.      Suppose the current buffer contains the text `foobarbar
  159.      haha!rara!'; then in this example the two substrings are `rbar '
  160.      and `rara!'.  The value is 2 because the first substring is greater
  161.      at the second character.
  162.           (compare-buffer-substring nil 6 11 nil 16 21)
  163.                => 2
  164. File: elisp,  Node: Insertion,  Next: Commands for Insertion,  Prev: Comparing Text,  Up: Text
  165. Inserting Text
  166. ==============
  167.    "Insertion" means adding new text to a buffer.  The inserted text
  168. goes at point--between the character before point and the character
  169. after point.
  170.    Insertion relocates markers that point at positions after the
  171. insertion point, so that they stay with the surrounding text (*note
  172. Markers::.).  When a marker points at the place of insertion, insertion
  173. normally doesn't relocate the marker, so that it points to the
  174. beginning of the inserted text; however, certain special functions such
  175. as `insert-before-markers' relocate such markers to point after the
  176. inserted text.
  177.    Some insertion functions leave point before the inserted text, while
  178. other functions leave it after.  We call the former insertion "after
  179. point" and the latter insertion "before point".
  180.    Insertion functions signal an error if the current buffer is
  181. read-only.
  182.    These functions copy text characters from strings and buffers along
  183. with their properties.  The inserted characters have exactly the same
  184. properties as the characters they were copied from.  By contrast,
  185. characters specified as separate arguments, not part of a string or
  186. buffer, inherit their text properties from the neighboring text.
  187.  - Function: insert &rest ARGS
  188.      This function inserts the strings and/or characters ARGS into the
  189.      current buffer, at point, moving point forward.  In other words, it
  190.      inserts the text before point.  An error is signaled unless all
  191.      ARGS are either strings or characters.  The value is `nil'.
  192.  - Function: insert-before-markers &rest ARGS
  193.      This function inserts the strings and/or characters ARGS into the
  194.      current buffer, at point, moving point forward.  An error is
  195.      signaled unless all ARGS are either strings or characters.  The
  196.      value is `nil'.
  197.      This function is unlike the other insertion functions in that it
  198.      relocates markers initially pointing at the insertion point, to
  199.      point after the inserted text.
  200.  - Function: insert-char CHARACTER COUNT &optional INHERIT
  201.      This function inserts COUNT instances of CHARACTER into the
  202.      current buffer before point.  The argument COUNT must be a number,
  203.      and CHARACTER must be a character.  The value is `nil'.
  204.      If INHERIT is non-`nil', then the inserted characters inherit
  205.      sticky text properties from the two characters before and after the
  206.      insertion point.  *Note Sticky Properties::.
  207.  - Function: insert-buffer-substring FROM-BUFFER-OR-NAME &optional
  208.           START END
  209.      This function inserts a portion of buffer FROM-BUFFER-OR-NAME
  210.      (which must already exist) into the current buffer before point.
  211.      The text inserted is the region from START and END.  (These
  212.      arguments default to the beginning and end of the accessible
  213.      portion of that buffer.)  This function returns `nil'.
  214.      In this example, the form is executed with buffer `bar' as the
  215.      current buffer.  We assume that buffer `bar' is initially empty.
  216.           ---------- Buffer: foo ----------
  217.           We hold these truths to be self-evident, that all
  218.           ---------- Buffer: foo ----------
  219.           
  220.           (insert-buffer-substring "foo" 1 20)
  221.                => nil
  222.           
  223.           ---------- Buffer: bar ----------
  224.           We hold these truth-!-
  225.           ---------- Buffer: bar ----------
  226.    *Note Sticky Properties::, for other insertion functions that inherit
  227. text properties from the nearby text in addition to inserting it.
  228. Whitespace inserted by indentation functions also inherits text
  229. properties.
  230. File: elisp,  Node: Commands for Insertion,  Next: Deletion,  Prev: Insertion,  Up: Text
  231. User-Level Insertion Commands
  232. =============================
  233.    This section describes higher-level commands for inserting text,
  234. commands intended primarily for the user but useful also in Lisp
  235. programs.
  236.  - Command: insert-buffer FROM-BUFFER-OR-NAME
  237.      This command inserts the entire contents of FROM-BUFFER-OR-NAME
  238.      (which must exist) into the current buffer after point.  It leaves
  239.      the mark after the inserted text.  The value is `nil'.
  240.  - Command: self-insert-command COUNT
  241.      This command inserts the last character typed; it does so COUNT
  242.      times, before point, and returns `nil'.  Most printing characters
  243.      are bound to this command.  In routine use, `self-insert-command'
  244.      is the most frequently called function in Emacs, but programs
  245.      rarely use it except to install it on a keymap.
  246.      In an interactive call, COUNT is the numeric prefix argument.
  247.      This command calls `auto-fill-function' whenever that is non-`nil'
  248.      and the character inserted is a space or a newline (*note Auto
  249.      Filling::.).
  250.      This command performs abbrev expansion if Abbrev mode is enabled
  251.      and the inserted character does not have word-constituent syntax.
  252.      (*Note Abbrevs::, and *Note Syntax Class Table::.)
  253.      This is also responsible for calling `blink-paren-function' when
  254.      the inserted character has close parenthesis syntax (*note
  255.      Blinking::.).
  256.  - Command: newline &optional NUMBER-OF-NEWLINES
  257.      This command inserts newlines into the current buffer before point.
  258.      If NUMBER-OF-NEWLINES is supplied, that many newline characters
  259.      are inserted.
  260.      This function calls `auto-fill-function' if the current column
  261.      number is greater than the value of `fill-column' and
  262.      NUMBER-OF-NEWLINES is `nil'.  Typically what `auto-fill-function'
  263.      does is insert a newline; thus, the overall result in this case is
  264.      to insert two newlines at different places: one at point, and
  265.      another earlier in the line.  `newline' does not auto-fill if
  266.      NUMBER-OF-NEWLINES is non-`nil'.
  267.      This command indents to the left margin if that is not zero.
  268.      *Note Margins::.
  269.      The value returned is `nil'.  In an interactive call, COUNT is the
  270.      numeric prefix argument.
  271.  - Command: split-line
  272.      This command splits the current line, moving the portion of the
  273.      line after point down vertically so that it is on the next line
  274.      directly below where it was before.  Whitespace is inserted as
  275.      needed at the beginning of the lower line, using the `indent-to'
  276.      function.  `split-line' returns the position of point.
  277.      Programs hardly ever use this function.
  278.  - Variable: overwrite-mode
  279.      This variable controls whether overwrite mode is in effect: a
  280.      non-`nil' value enables the mode.  It is automatically made
  281.      buffer-local when set in any fashion.
  282. File: elisp,  Node: Deletion,  Next: User-Level Deletion,  Prev: Commands for Insertion,  Up: Text
  283. Deleting Text
  284. =============
  285.    Deletion means removing part of the text in a buffer, without saving
  286. it in the kill ring (*note The Kill Ring::.).  Deleted text can't be
  287. yanked, but can be reinserted using the undo mechanism (*note Undo::.).
  288. Some deletion functions do save text in the kill ring in some special
  289. cases.
  290.    All of the deletion functions operate on the current buffer, and all
  291. return a value of `nil'.
  292.  - Function: erase-buffer
  293.      This function deletes the entire text of the current buffer,
  294.      leaving it empty.  If the buffer is read-only, it signals a
  295.      `buffer-read-only' error.  Otherwise, it deletes the text without
  296.      asking for any confirmation.  It returns `nil'.
  297.      Normally, deleting a large amount of text from a buffer inhibits
  298.      further auto-saving of that buffer "because it has shrunk".
  299.      However, `erase-buffer' does not do this, the idea being that the
  300.      future text is not really related to the former text, and its size
  301.      should not be compared with that of the former text.
  302.  - Command: delete-region START END
  303.      This command deletes the text in the current buffer in the region
  304.      defined by START and END.  The value is `nil'.  If point was
  305.      inside the deleted region, its value afterward is START.
  306.      Otherwise, point relocates with the surrounding text, as markers
  307.      do.
  308.  - Command: delete-char COUNT &optional KILLP
  309.      This command deletes COUNT characters directly after point, or
  310.      before point if COUNT is negative.  If KILLP is non-`nil', then it
  311.      saves the deleted characters in the kill ring.
  312.      In an interactive call, COUNT is the numeric prefix argument, and
  313.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  314.      argument is supplied, the text is saved in the kill ring.  If no
  315.      prefix argument is supplied, then one character is deleted, but
  316.      not saved in the kill ring.
  317.      The value returned is always `nil'.
  318.  - Command: delete-backward-char COUNT &optional KILLP
  319.      This command deletes COUNT characters directly before point, or
  320.      after point if COUNT is negative.  If KILLP is non-`nil', then it
  321.      saves the deleted characters in the kill ring.
  322.      In an interactive call, COUNT is the numeric prefix argument, and
  323.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  324.      argument is supplied, the text is saved in the kill ring.  If no
  325.      prefix argument is supplied, then one character is deleted, but
  326.      not saved in the kill ring.
  327.      The value returned is always `nil'.
  328.  - Command: backward-delete-char-untabify COUNT &optional KILLP
  329.      This command deletes COUNT characters backward, changing tabs into
  330.      spaces.  When the next character to be deleted is a tab, it is
  331.      first replaced with the proper number of spaces to preserve
  332.      alignment and then one of those spaces is deleted instead of the
  333.      tab.  If KILLP is non-`nil', then the command saves the deleted
  334.      characters in the kill ring.
  335.      Conversion of tabs to spaces happens only if COUNT is positive.
  336.      If it is negative, exactly -COUNT characters after point are
  337.      deleted.
  338.      In an interactive call, COUNT is the numeric prefix argument, and
  339.      KILLP is the unprocessed prefix argument.  Therefore, if a prefix
  340.      argument is supplied, the text is saved in the kill ring.  If no
  341.      prefix argument is supplied, then one character is deleted, but
  342.      not saved in the kill ring.
  343.      The value returned is always `nil'.
  344. File: elisp,  Node: User-Level Deletion,  Next: The Kill Ring,  Prev: Deletion,  Up: Text
  345. User-Level Deletion Commands
  346. ============================
  347.    This section describes higher-level commands for deleting text,
  348. commands intended primarily for the user but useful also in Lisp
  349. programs.
  350.  - Command: delete-horizontal-space
  351.      This function deletes all spaces and tabs around point.  It returns
  352.      `nil'.
  353.      In the following examples, we call `delete-horizontal-space' four
  354.      times, once on each line, with point between the second and third
  355.      characters on the line each time.
  356.           ---------- Buffer: foo ----------
  357.           I -!-thought
  358.           I -!-     thought
  359.           We-!- thought
  360.           Yo-!-u thought
  361.           ---------- Buffer: foo ----------
  362.           
  363.           (delete-horizontal-space)   ; Four times.
  364.                => nil
  365.           
  366.           ---------- Buffer: foo ----------
  367.           Ithought
  368.           Ithought
  369.           Wethought
  370.           You thought
  371.           ---------- Buffer: foo ----------
  372.  - Command: delete-indentation &optional JOIN-FOLLOWING-P
  373.      This function joins the line point is on to the previous line,
  374.      deleting any whitespace at the join and in some cases replacing it
  375.      with one space.  If JOIN-FOLLOWING-P is non-`nil',
  376.      `delete-indentation' joins this line to the following line
  377.      instead.  The value is `nil'.
  378.      If there is a fill prefix, and the second of the lines being joined
  379.      starts with the prefix, then `delete-indentation' deletes the fill
  380.      prefix before joining the lines.  *Note Margins::.
  381.      In the example below, point is located on the line starting
  382.      `events', and it makes no difference if there are trailing spaces
  383.      in the preceding line.
  384.           ---------- Buffer: foo ----------
  385.           When in the course of human
  386.           -!-    events, it becomes necessary
  387.           ---------- Buffer: foo ----------
  388.           
  389.           (delete-indentation)
  390.                => nil
  391.           ---------- Buffer: foo ----------
  392.           When in the course of human-!- events, it becomes necessary
  393.           ---------- Buffer: foo ----------
  394.      After the lines are joined, the function `fixup-whitespace' is
  395.      responsible for deciding whether to leave a space at the junction.
  396.  - Function: fixup-whitespace
  397.      This function replaces all the white space surrounding point with
  398.      either one space or no space, according to the context.  It
  399.      returns `nil'.
  400.      At the beginning or end of a line, the appropriate amount of space
  401.      is none.  Before a character with close parenthesis syntax, or
  402.      after a character with open parenthesis or expression-prefix
  403.      syntax, no space is also appropriate.  Otherwise, one space is
  404.      appropriate.  *Note Syntax Class Table::.
  405.      In the example below, `fixup-whitespace' is called the first time
  406.      with point before the word `spaces' in the first line.  For the
  407.      second invocation, point is directly after the `('.
  408.           ---------- Buffer: foo ----------
  409.           This has too many     -!-spaces
  410.           This has too many spaces at the start of (-!-   this list)
  411.           ---------- Buffer: foo ----------
  412.           (fixup-whitespace)
  413.                => nil
  414.           (fixup-whitespace)
  415.                => nil
  416.           ---------- Buffer: foo ----------
  417.           This has too many spaces
  418.           This has too many spaces at the start of (this list)
  419.           ---------- Buffer: foo ----------
  420.  - Command: just-one-space
  421.      This command replaces any spaces and tabs around point with a
  422.      single space.  It returns `nil'.
  423.  - Command: delete-blank-lines
  424.      This function deletes blank lines surrounding point.  If point is
  425.      on a blank line with one or more blank lines before or after it,
  426.      then all but one of them are deleted.  If point is on an isolated
  427.      blank line, then it is deleted.  If point is on a nonblank line,
  428.      the command deletes all blank lines following it.
  429.      A blank line is defined as a line containing only tabs and spaces.
  430.      `delete-blank-lines' returns `nil'.
  431. File: elisp,  Node: The Kill Ring,  Next: Undo,  Prev: User-Level Deletion,  Up: Text
  432. The Kill Ring
  433. =============
  434.    "Kill" functions delete text like the deletion functions, but save
  435. it so that the user can reinsert it by "yanking".  Most of these
  436. functions have `kill-' in their name.  By contrast, the functions whose
  437. names start with `delete-' normally do not save text for yanking
  438. (though they can still be undone); these are "deletion" functions.
  439.    Most of the kill commands are primarily for interactive use, and are
  440. not described here.  What we do describe are the functions provided for
  441. use in writing such commands.  You can use these functions to write
  442. commands for killing text.  When you need to delete text for internal
  443. purposes within a Lisp function, you should normally use deletion
  444. functions, so as not to disturb the kill ring contents.  *Note
  445. Deletion::.
  446.    Killed text is saved for later yanking in the "kill ring".  This is
  447. a list that holds a number of recent kills, not just the last text
  448. kill.  We call this a "ring" because yanking treats it as having
  449. elements in a cyclic order.  The list is kept in the variable
  450. `kill-ring', and can be operated on with the usual functions for lists;
  451. there are also specialized functions, described in this section, that
  452. treat it as a ring.
  453.    Some people think this use of the word "kill" is unfortunate, since
  454. it refers to operations that specifically *do not* destroy the entities
  455. "killed".  This is in sharp contrast to ordinary life, in which death
  456. is permanent and "killed" entities do not come back to life.
  457. Therefore, other metaphors have been proposed.  For example, the term
  458. "cut ring" makes sense to people who, in pre-computer days, used
  459. scissors and paste to cut up and rearrange manuscripts.  However, it
  460. would be difficult to change the terminology now.
  461. * Menu:
  462. * Kill Ring Concepts::     What text looks like in the kill ring.
  463. * Kill Functions::         Functions that kill text.
  464. * Yank Commands::          Commands that access the kill ring.
  465. * Low-Level Kill Ring::       Functions and variables for kill ring access.
  466. * Internals of Kill Ring:: Variables that hold kill-ring data.
  467. File: elisp,  Node: Kill Ring Concepts,  Next: Kill Functions,  Up: The Kill Ring
  468. Kill Ring Concepts
  469. ------------------
  470.    The kill ring records killed text as strings in a list, most recent
  471. first.  A short kill ring, for example, might look like this:
  472.      ("some text" "a different piece of text" "even older text")
  473. When the list reaches `kill-ring-max' entries in length, adding a new
  474. entry automatically deletes the last entry.
  475.    When kill commands are interwoven with other commands, each kill
  476. command makes a new entry in the kill ring.  Multiple kill commands in
  477. succession build up a single entry in the kill ring, which would be
  478. yanked as a unit; the second and subsequent consecutive kill commands
  479. add text to the entry made by the first one.
  480.    For yanking, one entry in the kill ring is designated the "front" of
  481. the ring.  Some yank commands "rotate" the ring by designating a
  482. different element as the "front."  But this virtual rotation doesn't
  483. change the list itself--the most recent entry always comes first in the
  484. list.
  485. File: elisp,  Node: Kill Functions,  Next: Yank Commands,  Prev: Kill Ring Concepts,  Up: The Kill Ring
  486. Functions for Killing
  487. ---------------------
  488.    `kill-region' is the usual subroutine for killing text.  Any command
  489. that calls this function is a "kill command" (and should probably have
  490. `kill' in its name).  `kill-region' puts the newly killed text in a new
  491. element at the beginning of the kill ring or adds it to the most recent
  492. element.  It uses the `last-command' variable to determine whether the
  493. previous command was a kill command, and if so appends the killed text
  494. to the most recent entry.
  495.  - Command: kill-region START END
  496.      This function kills the text in the region defined by START and
  497.      END.  The text is deleted but saved in the kill ring, along with
  498.      its text properties.  The value is always `nil'.
  499.      In an interactive call, START and END are point and the mark.
  500.      If the buffer is read-only, `kill-region' modifies the kill ring
  501.      just the same, then signals an error without modifying the buffer.
  502.      This is convenient because it lets the user use all the kill
  503.      commands to copy text into the kill ring from a read-only buffer.
  504.  - Command: copy-region-as-kill START END
  505.      This command saves the region defined by START and END on the kill
  506.      ring (including text properties), but does not delete the text
  507.      from the buffer.  It returns `nil'.  It also indicates the extent
  508.      of the text copied by moving the cursor momentarily, or by
  509.      displaying a message in the echo area.
  510.      The command does not set `this-command' to `kill-region', so a
  511.      subsequent kill command does not append to the same kill ring
  512.      entry.
  513.      Don't call `copy-region-as-kill' in Lisp programs unless you aim to
  514.      support Emacs 18.  For Emacs 19, it is better to use `kill-new' or
  515.      `kill-append' instead.  *Note Low-Level Kill Ring::.
  516. File: elisp,  Node: Yank Commands,  Next: Low-Level Kill Ring,  Prev: Kill Functions,  Up: The Kill Ring
  517. Functions for Yanking
  518. ---------------------
  519.    "Yanking" means reinserting an entry of previously killed text from
  520. the kill ring.  The text properties are copied too.
  521.  - Command: yank &optional ARG
  522.      This command inserts before point the text in the first entry in
  523.      the kill ring.  It positions the mark at the beginning of that
  524.      text, and point at the end.
  525.      If ARG is a list (which occurs interactively when the user types
  526.      `C-u' with no digits), then `yank' inserts the text as described
  527.      above, but puts point before the yanked text and puts the mark
  528.      after it.
  529.      If ARG is a number, then `yank' inserts the ARGth most recently
  530.      killed text--the ARGth element of the kill ring list.
  531.      `yank' does not alter the contents of the kill ring or rotate it.
  532.      It returns `nil'.
  533.  - Command: yank-pop ARG
  534.      This command replaces the just-yanked entry from the kill ring
  535.      with a different entry from the kill ring.
  536.      This is allowed only immediately after a `yank' or another
  537.      `yank-pop'.  At such a time, the region contains text that was just
  538.      inserted by yanking.  `yank-pop' deletes that text and inserts in
  539.      its place a different piece of killed text.  It does not add the
  540.      deleted text to the kill ring, since it is already in the kill
  541.      ring somewhere.
  542.      If ARG is `nil', then the replacement text is the previous element
  543.      of the kill ring.  If ARG is numeric, the replacement is the ARGth
  544.      previous kill.  If ARG is negative, a more recent kill is the
  545.      replacement.
  546.      The sequence of kills in the kill ring wraps around, so that after
  547.      the oldest one comes the newest one, and before the newest one
  548.      goes the oldest.
  549.      The value is always `nil'.
  550. File: elisp,  Node: Low-Level Kill Ring,  Next: Internals of Kill Ring,  Prev: Yank Commands,  Up: The Kill Ring
  551. Low-Level Kill Ring
  552. -------------------
  553.    These functions and variables provide access to the kill ring at a
  554. lower level, but still convenient for use in Lisp programs.  They take
  555. care of interaction with X Window selections.  They do not exist in
  556. Emacs version 18.
  557.  - Function: current-kill N &optional DO-NOT-MOVE
  558.      The function `current-kill' rotates the yanking pointer which
  559.      designates the "front" of the kill ring by N places (from newer
  560.      kills to older ones), and returns the text at that place in the
  561.      ring.
  562.      If the optional second argument DO-NOT-MOVE is non-`nil', then
  563.      `current-kill' doesn't alter the yanking pointer; it just returns
  564.      the Nth kill, counting from the current yanking pointer.
  565.      If N is zero, indicating a request for the latest kill,
  566.      `current-kill' calls the value of `interprogram-paste-function'
  567.      (documented below) before consulting the kill ring.
  568.  - Function: kill-new STRING
  569.      This function puts the text STRING into the kill ring as a new
  570.      entry at the front of the ring.  It discards the oldest entry if
  571.      appropriate.  It also invokes the value of
  572.      `interprogram-cut-function' (see below).
  573.  - Function: kill-append STRING BEFORE-P
  574.      This function appends the text STRING to the first entry in the
  575.      kill ring.  Normally STRING goes at the end of the entry, but if
  576.      BEFORE-P is non-`nil', it goes at the beginning.  This function
  577.      also invokes the value of `interprogram-cut-function' (see below).
  578.  - Variable: interprogram-paste-function
  579.      This variable provides a way of transferring killed text from other
  580.      programs, when you are using a window system.  Its value should be
  581.      `nil' or a function of no arguments.
  582.      If the value is a function, `current-kill' calls it to get the
  583.      "most recent kill".  If the function returns a non-`nil' value,
  584.      then that value is used as the "most recent kill".  If it returns
  585.      `nil', then the first element of `kill-ring' is used.
  586.      The normal use of this hook is to get the X server's primary
  587.      selection as the most recent kill, even if the selection belongs
  588.      to another X client.  *Note X Selections::.
  589.  - Variable: interprogram-cut-function
  590.      This variable provides a way of communicating killed text to other
  591.      programs, when you are using a window system.  Its value should be
  592.      `nil' or a function of one argument.
  593.      If the value is a function, `kill-new' and `kill-append' call it
  594.      with the new first element of the kill ring as an argument.
  595.      The normal use of this hook is to set the X server's primary
  596.      selection to the newly killed text.
  597. File: elisp,  Node: Internals of Kill Ring,  Prev: Low-Level Kill Ring,  Up: The Kill Ring
  598. Internals of the Kill Ring
  599. --------------------------
  600.    The variable `kill-ring' holds the kill ring contents, in the form
  601. of a list of strings.  The most recent kill is always at the front of
  602. the list.
  603.    The `kill-ring-yank-pointer' variable points to a link in the kill
  604. ring list, whose CAR is the text to yank next.  We say it identifies
  605. the "front" of the ring.  Moving `kill-ring-yank-pointer' to a
  606. different link is called "rotating the kill ring".  We call the kill
  607. ring a "ring" because the functions that move the yank pointer wrap
  608. around from the end of the list to the beginning, or vice-versa.
  609. Rotation of the kill ring is virtual; it does not change the value of
  610. `kill-ring'.
  611.    Both `kill-ring' and `kill-ring-yank-pointer' are Lisp variables
  612. whose values are normally lists.  The word "pointer" in the name of the
  613. `kill-ring-yank-pointer' indicates that the variable's purpose is to
  614. identify one element of the list for use by the next yank command.
  615.    The value of `kill-ring-yank-pointer' is always `eq' to one of the
  616. links in the kill ring list.  The element it identifies is the CAR of
  617. that link.  Kill commands, which change the kill ring, also set this
  618. variable to the value of `kill-ring'.  The effect is to rotate the ring
  619. so that the newly killed text is at the front.
  620.    Here is a diagram that shows the variable `kill-ring-yank-pointer'
  621. pointing to the second entry in the kill ring `("some text" "a
  622. different piece of text" "yet older text")'.
  623.      kill-ring       kill-ring-yank-pointer
  624.        |               |
  625.        |     ___ ___    --->  ___ ___      ___ ___
  626.         --> |___|___|------> |___|___|--> |___|___|--> nil
  627.               |                |            |
  628.               |                |            |
  629.               |                |             -->"yet older text"
  630.               |                |
  631.               |                 --> "a different piece of text"
  632.               |
  633.                --> "some text"
  634. This state of affairs might occur after `C-y' (`yank') immediately
  635. followed by `M-y' (`yank-pop').
  636.  - Variable: kill-ring
  637.      This variable holds the list of killed text sequences, most
  638.      recently killed first.
  639.  - Variable: kill-ring-yank-pointer
  640.      This variable's value indicates which element of the kill ring is
  641.      at the "front" of the ring for yanking.  More precisely, the value
  642.      is a tail of the value of `kill-ring', and its CAR is the kill
  643.      string that `C-y' should yank.
  644.  - User Option: kill-ring-max
  645.      The value of this variable is the maximum length to which the kill
  646.      ring can grow, before elements are thrown away at the end.  The
  647.      default value for `kill-ring-max' is 30.
  648. File: elisp,  Node: Undo,  Next: Maintaining Undo,  Prev: The Kill Ring,  Up: Text
  649.    Most buffers have an "undo list", which records all changes made to
  650. the buffer's text so that they can be undone.  (The buffers that don't
  651. have one are usually special-purpose buffers for which Emacs assumes
  652. that undoing is not useful.)  All the primitives that modify the text
  653. in the buffer automatically add elements to the front of the undo list,
  654. which is in the variable `buffer-undo-list'.
  655.  - Variable: buffer-undo-list
  656.      This variable's value is the undo list of the current buffer.  A
  657.      value of `t' disables the recording of undo information.
  658.    Here are the kinds of elements an undo list can have:
  659. `INTEGER'
  660.      This kind of element records a previous value of point.  Ordinary
  661.      cursor motion does not get any sort of undo record, but deletion
  662.      commands use these entries to record where point was before the
  663.      command.
  664. `(BEG . END)'
  665.      This kind of element indicates how to delete text that was
  666.      inserted.  Upon insertion, the text occupied the range BEG-END in
  667.      the buffer.
  668. `(TEXT . POSITION)'
  669.      This kind of element indicates how to reinsert text that was
  670.      deleted.  The deleted text itself is the string TEXT.  The place to
  671.      reinsert it is `(abs POSITION)'.
  672. `(t HIGH . LOW)'
  673.      This kind of element indicates that an unmodified buffer became
  674.      modified.  The elements HIGH and LOW are two integers, each
  675.      recording 16 bits of the visited file's modification time as of
  676.      when it was previously visited or saved.  `primitive-undo' uses
  677.      those values to determine whether to mark the buffer as unmodified
  678.      once again; it does so only if the file's modification time
  679.      matches those numbers.
  680. `(nil PROPERTY VALUE BEG . END)'
  681.      This kind of element records a change in a text property.  Here's
  682.      how you might undo the change:
  683.           (put-text-property BEG END PROPERTY VALUE)
  684. `(MARKER . ADJUSTMENT)'
  685.      This kind of element records the fact that the marker MARKER was
  686.      relocated due to deletion of surrounding text, and that it moved
  687.      ADJUSTMENT character positions.  Undoing this element moves MARKER
  688.      - ADJUSTMENT characters.
  689. `POSITION'
  690.      This element indicates where point was at an earlier time.
  691.      Undoing this element sets point to POSITION.  Deletion normally
  692.      creates an element of this kind as well as a reinsertion element.
  693. `nil'
  694.      This element is a boundary.  The elements between two boundaries
  695.      are called a "change group"; normally, each change group
  696.      corresponds to one keyboard command, and undo commands normally
  697.      undo an entire group as a unit.
  698.  - Function: undo-boundary
  699.      This function places a boundary element in the undo list.  The undo
  700.      command stops at such a boundary, and successive undo commands undo
  701.      to earlier and earlier boundaries.  This function returns `nil'.
  702.      The editor command loop automatically creates an undo boundary
  703.      before each key sequence is executed.  Thus, each undo normally
  704.      undoes the effects of one command.  Self-inserting input
  705.      characters are an exception.  The command loop makes a boundary
  706.      for the first such character; the next 19 consecutive
  707.      self-inserting input characters do not make boundaries, and then
  708.      the 20th does, and so on as long as self-inserting characters
  709.      continue.
  710.      All buffer modifications add a boundary whenever the previous
  711.      undoable change was made in some other buffer.  This way, a
  712.      command that modifies several buffers makes a boundary in each
  713.      buffer it changes.
  714.      Calling this function explicitly is useful for splitting the
  715.      effects of a command into more than one unit.  For example,
  716.      `query-replace' calls `undo-boundary' after each replacement, so
  717.      that the user can undo individual replacements one by one.
  718.  - Function: primitive-undo COUNT LIST
  719.      This is the basic function for undoing elements of an undo list.
  720.      It undoes the first COUNT elements of LIST, returning the rest of
  721.      LIST.  You could write this function in Lisp, but it is convenient
  722.      to have it in C.
  723.      `primitive-undo' adds elements to the buffer's undo list when it
  724.      changes the buffer.  Undo commands avoid confusion by saving the
  725.      undo list value at the beginning of a sequence of undo operations.
  726.      Then the undo operations use and update the saved value.  The new
  727.      elements added by undoing are not part of this saved value, so
  728.      they don't interfere with continuing to undo.
  729. File: elisp,  Node: Maintaining Undo,  Next: Filling,  Prev: Undo,  Up: Text
  730. Maintaining Undo Lists
  731. ======================
  732.    This section describes how to enable and disable undo information for
  733. a given buffer.  It also explains how the undo list is truncated
  734. automatically so it doesn't get too big.
  735.    Recording of undo information in a newly created buffer is normally
  736. enabled to start with; but if the buffer name starts with a space, the
  737. undo recording is initially disabled.  You can explicitly enable or
  738. disable undo recording with the following two functions, or by setting
  739. `buffer-undo-list' yourself.
  740.  - Command: buffer-enable-undo &optional BUFFER-OR-NAME
  741.      This command enables recording undo information for buffer
  742.      BUFFER-OR-NAME, so that subsequent changes can be undone.  If no
  743.      argument is supplied, then the current buffer is used.  This
  744.      function does nothing if undo recording is already enabled in the
  745.      buffer.  It returns `nil'.
  746.      In an interactive call, BUFFER-OR-NAME is the current buffer.  You
  747.      cannot specify any other buffer.
  748.  - Function: buffer-disable-undo &optional BUFFER
  749.  - Function: buffer-flush-undo &optional BUFFER
  750.      This function discards the undo list of BUFFER, and disables
  751.      further recording of undo information.  As a result, it is no
  752.      longer possible to undo either previous changes or any subsequent
  753.      changes.  If the undo list of BUFFER is already disabled, this
  754.      function has no effect.
  755.      This function returns `nil'.  It cannot be called interactively.
  756.      The name `buffer-flush-undo' is not considered obsolete, but the
  757.      preferred name `buffer-disable-undo' is new as of Emacs versions
  758.      19.
  759.    As editing continues, undo lists get longer and longer.  To prevent
  760. them from using up all available memory space, garbage collection trims
  761. them back to size limits you can set.  (For this purpose, the "size" of
  762. an undo list measures the cons cells that make up the list, plus the
  763. strings of deleted text.)  Two variables control the range of acceptable
  764. sizes: `undo-limit' and `undo-strong-limit'.
  765.  - Variable: undo-limit
  766.      This is the soft limit for the acceptable size of an undo list.
  767.      The change group at which this size is exceeded is the last one
  768.      kept.
  769.  - Variable: undo-strong-limit
  770.      This is the upper limit for the acceptable size of an undo list.
  771.      The change group at which this size is exceeded is discarded
  772.      itself (along with all older change groups).  There is one
  773.      exception: the very latest change group is never discarded no
  774.      matter how big it is.
  775. File: elisp,  Node: Filling,  Next: Margins,  Prev: Maintaining Undo,  Up: Text
  776. Filling
  777. =======
  778.    "Filling" means adjusting the lengths of lines (by moving the line
  779. breaks) so that they are nearly (but no greater than) a specified
  780. maximum width.  Additionally, lines can be "justified", which means
  781. inserting spaces to make the left and/or right margins line up
  782. precisely.  The width is controlled by the variable `fill-column'.  For
  783. ease of reading, lines should be no longer than 70 or so columns.
  784.    You can use Auto Fill mode (*note Auto Filling::.) to fill text
  785. automatically as you insert it, but changes to existing text may leave
  786. it improperly filled.  Then you must fill the text explicitly.
  787.    Most of the commands in this section return values that are not
  788. meaningful.  All the functions that do filling take note of the current
  789. left margin, current right margin, and current justification style
  790. (*note Margins::.).  If the current justification style is `none', the
  791. filling functions don't actually do anything.
  792.    Several of the filling functions have an argument JUSTIFY.  If it is
  793. non-`nil', that requests some kind of justification.  It can be `left',
  794. `right', `full', or `center', to request a specific style of
  795. justification.  If it is `t', that means to use the current
  796. justification style for this part of the text (see
  797. `current-justification', below).
  798.    When you call the filling functions interactively, using a prefix
  799. argument implies the value `full' for JUSTIFY.
  800.  - Command: fill-paragraph JUSTIFY
  801.      This command fills the paragraph at or after point.  If JUSTIFY is
  802.      non-`nil', each line is justified as well.  It uses the ordinary
  803.      paragraph motion commands to find paragraph boundaries.  *Note
  804.      Paragraphs: (emacs)Paragraphs.
  805.  - Command: fill-region START END &optional JUSTIFY
  806.      This command fills each of the paragraphs in the region from START
  807.      to END.  It justifies as well if JUSTIFY is non-`nil'.
  808.      The variable `paragraph-separate' controls how to distinguish
  809.      paragraphs.  *Note Standard Regexps::.
  810.  - Command: fill-individual-paragraphs START END &optional JUSTIFY
  811.           MAIL-FLAG
  812.      This command fills each paragraph in the region according to its
  813.      individual fill prefix.  Thus, if the lines of a paragraph were
  814.      indented with spaces, the filled paragraph will remain indented in
  815.      the same fashion.
  816.      The first two arguments, START and END, are the beginning and end
  817.      of the region to be filled.  The third and fourth arguments,
  818.      JUSTIFY and MAIL-FLAG, are optional.  If JUSTIFY is non-`nil', the
  819.      paragraphs are justified as well as filled.  If MAIL-FLAG is
  820.      non-`nil', it means the function is operating on a mail message
  821.      and therefore should not fill the header lines.
  822.      Ordinarily, `fill-individual-paragraphs' regards each change in
  823.      indentation as starting a new paragraph.  If
  824.      `fill-individual-varying-indent' is non-`nil', then only separator
  825.      lines separate paragraphs.  That mode can handle indented
  826.      paragraphs with additional indentation on the first line.
  827.  - User Option: fill-individual-varying-indent
  828.      This variable alters the action of `fill-individual-paragraphs' as
  829.      described above.
  830.  - Command: fill-region-as-paragraph START END &optional JUSTIFY
  831.      This command considers a region of text as a paragraph and fills
  832.      it.  If the region was made up of many paragraphs, the blank lines
  833.      between paragraphs are removed.  This function justifies as well
  834.      as filling when JUSTIFY is non-`nil'.
  835.      In an interactive call, any prefix argument requests justification.
  836.      In Adaptive Fill mode, which is enabled by default, calling the
  837.      function `fill-region-as-paragraph' on an indented paragraph when
  838.      there is no fill prefix uses the indentation of the second line of
  839.      the paragraph as the fill prefix.
  840.  - Command: justify-current-line HOW EOP NOSQUEEZE
  841.      This command inserts spaces between the words of the current line
  842.      so that the line ends exactly at `fill-column'.  It returns `nil'.
  843.      The argument HOW, if non-`nil' specifies explicitly the style of
  844.      justification.  It can be `left', `right', `full', `center', or
  845.      `none'.  If it is `t', that means to do follow specified
  846.      justification style (see `current-justification', below).  `nil'
  847.      means to do full justification.
  848.      If EOP is non-`nil', that means do left-justification if
  849.      `current-justification' specifies full justification.  This is used
  850.      for the last line of a paragraph; even if the paragraph as a whole
  851.      is fully justified, the last line should not be.
  852.      If NOSQUEEZE is non-`nil', that means do not change interior
  853.      whitespace.
  854.  - User Option: default-justification
  855.      This variable's value specifies the style of justification to use
  856.      for text that doesn't specify a style with a text property.  The
  857.      possible values are `left', `right', `full', `center', or `none'.
  858.      The default value is `left'.
  859.  - Function: current-justification
  860.      This function returns the proper justification style to use for
  861.      filling the text around point.
  862.  - Variable: fill-paragraph-function
  863.      This variable provides a way for major modes to override the
  864.      filling of paragraphs.  If the value is non-`nil',
  865.      `fill-paragraph' calls this function to do the work.  If the
  866.      function returns a non-`nil' value, `fill-paragraph' assumes the
  867.      job is done, and immediately returns that value.
  868.      The usual use of this feature is to fill comments in programming
  869.      language modes.  If the function needs to fill a paragraph in the
  870.      usual way, it can do so as follows:
  871.           (let ((fill-paragraph-function nil))
  872.             (fill-paragraph arg))
  873.  - Variable: use-hard-newlines
  874.      If this variable is non-`nil', the filling functions do not delete
  875.      newlines that have the `hard' text property.  These "hard
  876.      newlines" act as paragraph separators.
  877.